package com.common.frame.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;



public class NetUtil {

    private static ConnectivityManager connectivityManager =
            (ConnectivityManager) AppGlobals.getApplication().getSystemService(Context.CONNECTIVITY_SERVICE);

    /**
     * 检查当前网络是否可用
     *
     * @return 是否连接到网络
     */
    public static boolean isNetworkAvailable() {
        if (connectivityManager != null) {
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            if (info != null && info.isConnected()) {
                if (info.getState() == NetworkInfo.State.CONNECTED) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean isWifi(){
        if (connectivityManager != null) {
            NetworkInfo info = connectivityManager.getActiveNetworkInfo();
            return info!= null && info.getType() == ConnectivityManager.TYPE_WIFI;
        }
        return false;
    }


}
